// pages/privacy_business/privacy_business.js
const app = getApp(), core = require('../../utils/core');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    blacklist: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    core.get({url:'xilujob.company/company_blacklist',success:ret=>{
      this.setData({blacklist: ret.data});
    }});
  },
  bindAddBlacklist() {
    if(this.data.blacklist.length>=5) {
      wx.showToast({title: '最多添加5个'});
      return;
    }
    wx.navigateTo({
      url: '/pages/search_privacy/search_privacy',
      events: {
        dataTransfer: data => {
          let addedList = data.addedList;
          this.setData({blacklist: this.data.blacklist.concat(addedList)});
        }
      }
    })
  },
  bindRemoveBlacklist(event) {
    let index = event.currentTarget.dataset.index,
      companyId = this.data.blacklist[index].id;
    core.post({url:'xilujob.company/set_blacklist_company',data:{company_ids:[companyId]},success:ret=>{
      this.data.blacklist.splice(index,1);
      this.setData({blacklist: this.data.blacklist});
    }});
  }


});
